package com.ptszyxx.popose.module.main.mine.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.ptszyxx.popose.BuildConfig;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.data.entity.mine.VersionEntity;
import com.ysg.utils.YSPUtils;
import com.ysg.utils.YToastUtil;

import java.util.HashMap;
import java.util.Map;

public class MineSetVM extends BaseViewModel<CommonRepository> {

    public MineSetVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onLogoutEvent = new SingleLiveEvent<>();
        public SingleLiveEvent onClearCacheEvent = new SingleLiveEvent<>();
        public SingleLiveEvent onUpdateVersionEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onAccountCommand = new BindingCommand(()-> YActivityUtil.getInstance().jumpMineAccount(this));
    public BindingCommand onLogoutCommand = new BindingCommand(() -> uc.onLogoutEvent.call());
    public BindingCommand onClearCacheCommand = new BindingCommand(() -> uc.onClearCacheEvent.call());
    public BindingCommand onUpdateVersionCommand = new BindingCommand(() -> requestVersion());
    public BindingCommand onPriceCommand = new BindingCommand(() -> YActivityUtil.getInstance().jumpMinePrice(this));
    public BindingCommand onPushCommand = new BindingCommand((o) -> YSPUtils.getInstance().put("pushOpen", (Boolean) o));

    //=========================================接口：start===========================================

    /**
     * 版本
     */
    public void requestVersion(){
        YToastUtil.showShort("已是最新版本");
//        Map<String, String> map = new HashMap<>();
//        map.put("qudaoid", "3");
//        map.put("verint", String.valueOf(BuildConfig.VERSION_CODE));
//        HttpUtils.getInstance()
//                .data(model.versionInfo(map), this, new OnSuccessResult<VersionEntity>() {
//                    @Override
//                    public void onSuccessResult(BaseResponse<VersionEntity> response) {
//                        uc.onUpdateVersionEvent.setValue(response.getData());
//                    }
//                });
    }

}
